package com.hd.controller;

import com.hd.pojo.InstrResultInfo;
import com.hd.pojo.ReservationInstr;
import com.hd.service.InstrResultInfoService;
import com.hd.service.ReservationInstrService;
import com.hd.tools.Log;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;

/**
 * Created by 1 on 2017/12/1.
 */
@Controller
@RequestMapping("/director/enterTreatmentInstr")
public class EnterTreatmentInstrController {

    private String msg;

    @Resource
    private ReservationInstrService reservationInstrService;

    @Resource
    private InstrResultInfoService instrResultInfoService;

    @GetMapping("/searchReserInstrNotEnter")
    public String searchReserInstrNotEnter(Model model){
        ReservationInstr ri = reservationInstrService.searchReserInstrNotEnter();
        model.addAttribute("ri",ri);
        return "director/enterTreatmentInstr";
    }

    @ResponseBody
    @PostMapping("/addRerInstr")
    public String addRerInstr(InstrResultInfo instrResultInfo){
        instrResultInfo.setOperDate(LocalDateTime.now());
        try{
            instrResultInfoService.addInstrResultInfo(instrResultInfo);
            msg = "仪器诊断结果录入成功!";
        }catch (Exception ex){
            msg = "仪器诊断结果录入失败!";
            Log.logger.error(msg,ex);
        }
        return msg;
    }

}
